-
Notifications
You must be signed in to change notification settings - Fork 89
Add write protection with examples and tests #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| $description = trim(fgets(STDIN)); | ||
|
|
||
| // Set channel metadata | ||
| $pubnub->setChannelMetadata() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering how useful this can be for SDK user.
? What do you think about following approach:
<?php
set_time_limit(0);
require('../../vendor/autoload.php');
use PubNub\PNConfiguration;
use PubNub\PubNub;
$pnconf = new PNConfiguration();
$pnconf->setPublishKey("demo");
$pnconf->setSubscribeKey("demo");
$pnconf->setUuid("example");
$pubnub = new PubNub($pnconf);
$channel = "demo_example";
$channelName = "Channel1on1";
$channelDescription = "Channel for 1on1 conversation";
$status = "active";
$type = "1on1";
$initialCustom = ["Days" => "Mon-Fri"];
// Set initial channel metadata
$pubnub->setChannelMetadata()
->channel($channel)
->name($channelName)
->description($channelDescription)
->meta(["custom" => $initialCustom])
->status($status)
->type($type)
->sync();
// Fetch the current metadata
$response = $pubnub->getChannelMetadata()
->channel($channel)
->includeCustom(true)
->sync();
$custom = (array)$response->getCustom();
$additionalMetadata = ["Months" => "Jan-May"];
// Merge additional metadata
$updatedCustomMetadata = array_merge($custom, $additionalMetadata);
// Update the channel metadata
$updatedMetadata = $pubnub->setChannelMetadata()
->channel($channel)
->custom($updatedCustomMetadata)
->includeCustom(true)
->sync();
print("Updated channel metadata:");
print_r($updatedMetadata->getData());
// Cleanup
$pubnub->removeChannelMetadata()
->channel($channel)
->sync();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it in a different PR because it seems that this SDK misses some features and I have to look into it
| * @param string $prev | ||
| * @param string $next | ||
| * @param array $data | ||
| * @param $string $eTag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
@param ?string $eTag
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| if (!empty($data)) | ||
| { | ||
| $data_string = json_encode($data); | ||
| if (!empty($data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be:
if (!empty($this->data)) {
$data_string = json_encode($this->data);
} else {
$data_string = 'null';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. copypaste ;) fixed..
|
|
||
| foreach($payload["data"] as $value) | ||
| { | ||
| foreach ($payload["data"] as $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this possible that data is null here?
If so array_push may fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem with that because on line 120 I create an empty array for data and if the $payload is not iterable. the worst thing may be an warning about undefined key, but I guess somewhere higher the key is always defined at least as null
|
@pubnub-release-bot release |
|
🚀 Release successfully completed 🚀 |
feat: Write protection with If-Match eTag header
Write protection with If-Match eTag header for setting channel and uuid metadata